def target_sum(nums, target):
    num_sum = sum(nums)
    new_target = target + num_sum
    if new_target % 2 == 1:
        return -1
    new_target //= 2
    return ways(nums, new_target)


def ways(nums, target):
    # dp = len(nums)+1 * (target + 1)
    n = len(nums)
    dp = [[0]*(target+1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(1, n+1):
        num = nums[i-1]
        for j in range(0, target+1):
            if num > j:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = dp[i-1][j] + dp[i-1][j-num]
    return dp[n][target]

print(target_sum([1, 2, 3, 4, 5], 11))